package com.aaa.qy127.controller;

import com.aaa.qy127.entity.Ruku;
import com.aaa.qy127.entity.Staff;
import com.aaa.qy127.service.RukuService;
import com.aaa.qy127.service.impl.RukuServiceImpl;
import com.aaa.qy127.util.Result;
import com.alibaba.fastjson.JSON;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/ruku")
public class RukuController {
    RukuService rukuService = new RukuServiceImpl();
    /**
     * 查询入库信息
     * @param ruku
     * @return
     */
    @RequestMapping("/list")
    public Result queryAllruku(Ruku ruku){
        Result result = rukuService.queryAllruku(ruku);
        return result;
    }
    /**
     * 查询一条入库信息详情
     * @param ruku
     * @return
     */
    @RequestMapping("/xiangqing")
    public Result getoneruku(Ruku ruku){
        Result result = rukuService.getoneruku(ruku);
        return result;
    }

    /**
     * 添加入库单
     * @param data
     * @param tableData
     * @param request
     * @return
     */
    @RequestMapping("/addruku")
    public String addruku(String data, String tableData, HttpServletRequest request){
        Staff staff = (Staff) request.getSession().getAttribute("staff");
        HashMap map = JSON.parseObject(data, HashMap.class);
        List<Map<String,Object>> maps = (List<Map<String,Object>>) JSON.parse(tableData);
        String addruku = rukuService.addruku(map, maps, staff.getId());
        return addruku;
    }
}
